import { IPSSysDBColumn } from './ipssys-dbcolumn';
import { IPSSysDBIndexColumn } from './ipssys-dbindex-column';
import { IPSSysDBTable } from './ipssys-dbtable';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSSysDBIndexColumnImpl extends PSModelObjectImpl implements IPSSysDBIndexColumn {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get length(): number {
    return this.M.length != null ? this.M.length : -1;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected pssysdbcolumn: IPSSysDBColumn | null = null;

  getPSSysDBColumn(): IPSSysDBColumn | null {
    if (this.pssysdbcolumn != null) return this.pssysdbcolumn;
    const value = this.M.getPSSysDBColumn;
    if (value == null) {
      return null;
    }
    const ipssysdbtable = this.getParentPSModelObject('database.IPSSysDBTable') as IPSSysDBTable;
    if (ipssysdbtable != null) {
      this.pssysdbcolumn = ipssysdbtable.findPSSysDBColumn(value);
    }
    return this.pssysdbcolumn;
  }

  get psSysDBColumn(): IPSSysDBColumn | null {
    return this.getPSSysDBColumn();
  }

  getPSSysDBColumnMust(): IPSSysDBColumn {
    const value = this.getPSSysDBColumn();
    if (value == null) {
      throw new Error('未指定索引列');
    }
    return value;
  }

  get sortDir(): 'ASC' | 'DESC' {
    return this.M.sortDir;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get includeMode(): boolean {
    return this.M.includeMode != null ? this.M.includeMode : false;
  }

  get cls(): string {
    return 'PSSysDBIndexColumnImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'database.IPSDBIndexColumnBase' || cls == 'database.IPSSysDBIndexColumn') return true;
    return super.instanceof(cls);
  }
}
